<?php
namespace Admin\Controller;
use Think\Controller;
class CommonController extends AdminController {
	//添加图片页面
    public function add_image(){
        $this->display();
    }
    //添加图片
    public function add(){
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize   =     66145728 ;// 设置附件上传大小
        $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath  =     './Upload/'; // 设置附件上传根目录
        $upload->savePath  =     '/'; // 设置附件上传（子）目录
        // 上传文件 
        $info = $upload->upload();
        if(!$info) {// 上传错误提示错误信息
            $data['info']=$upload->getError();
            $data['status']=2;
            $this->ajaxReturn($data);
        }else{// 上传成功
            $data['status']=1;
            $data['image']=$info['uploadFile']['savepath'].$info['uploadFile']['savename'];
            $this->ajaxReturn($data);
        }
    }
    //取消图片根据路径删除图片
    public function del_image(){
        $path = '.'.I('path');
        if(file_exists($path)){
            if(@unlink($path)){
                $this->ajaxReturn(V(1,'图片已取消'));
            }else{
                $this->ajaxReturn(V(2,'图片未取消'));
            }
        }else{
            $this->ajaxReturn(V(3,'未检测到图片'));
        }
    }
}